Skip to content

Conversation

@ingydotnet
Copy link
Contributor

Refactored the Makefile in 15 commits, with details in each commit message.

Found and fixed some bugs along the way.

All previous targets should work as before.

Copy link
Contributor

@jfhamlin jfhamlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the cleanup! looks awesome and works well :). just had a few questions/nits and then i think we're good to merge!


SHELL := bash

GO-VERSION ?= 1.19.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the switch from SNAKE_CASE to KEBAB-CASE? i've seen kebab for targets but snake seems like the norm for variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if you read through my explanations in the commit messages, but 7f2d72d

Makefiles inherit from the env which only allows SNAKE_CASE. KEBAB-BASE is only allowed in Makefile vars, not env ones, so it makes the vars ownership very clear.

You can override vars from the command line like this:

ENV_VAR=foo make all MAKE-VAR=bar

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in commit 1b0f4cd I made almost all of the SINGLEWORD Makefile vars into MULTI-WORD vars, to drive home that they don't ever come from (can't come from) the environment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair point! don't feel strongly, but i wanted to understand the motivation and i failed to read the (useful!) commit messages :)

STDLIB-ORIGINALS-DIR := scripts/rewrite-core/originals
STDLIB-ORIGINALS := $(wildcard $(STDLIB-ORIGINALS-DIR)/*.clj)
STDLIB-NAMES := $(STDLIB-ORIGINALS:scripts/rewrite-core/originals/%=%)
STDLIB-ORIGINALS := $(STDLIB-NAMES:%=scripts/rewrite-core/originals/,%)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#-------------------------------------------------------------------------------
default: all

.PHONY: all
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep the .PHONY declarations for the targets that don't produce files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. .PHONY is not only noisy and useless. I found out from this refactor that it can be dangerous.

Here https://github.com/glojurelang/glojure/blob/main/Makefile#L44 all deps on go-generate but that target doesn't exist. The Makefile should error but it doesn't because https://github.com/glojurelang/glojure/blob/main/Makefile#L52 marks go-generate as PHONY.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See commit messages:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw i've been bitten by missing .PHONY before, but i don't feel strongly. happy to run with this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me too, but those bites are rare and almost instantly recognized.
The bite I described (where PHONY masked a typo) remained hidden for a while.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an interesting fact about PHONY you might now know...

You can put all your PHONY targets on one line at the end of the file if you want:

.PHONY: all test clean etc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can put all your PHONY targets on one line at the end of the file if you want:

ah, i'm familiar with that, but i prefer to keep them adjacent to their targets so it's harder for them to get out of sync — which i managed to do with one of the targets anyway :)

@ingydotnet ingydotnet requested a review from jfhamlin September 25, 2025 04:58
@ingydotnet
Copy link
Contributor Author

thanks for the cleanup! looks awesome and works well :). just had a few questions/nits and then i think we're good to merge!

Thanks! FWIW, I learned a few new Makefile tricks from your work along the way. 👍

Copy link
Contributor

@jfhamlin jfhamlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarifications! I'll merge after CI finishes :)

@ingydotnet
Copy link
Contributor Author

I can resolve if you want...

@ingydotnet
Copy link
Contributor Author

ingydotnet commented Sep 25, 2025

Let me know.

@jfhamlin
Copy link
Contributor

I can resolve if you want...

ah, please do if you don't mind!

I was getting failures for `make test` until I realized I hadn't pulled
the test suite submodule.

Now we always update submodules first so should work for everyone.

Added report.html to clean target and ignored it.
Setting SHELL to bash allows us to make use of a more dependable
environment. It also allows us to use bash syntax which in many cases is
cleaner because you don't need to be concerned with supporting any
shell.

`bash` is preferable to `/bin/bash` since it will pick up possibly more
preferable bash version from the PATH. Like on macOS, /bin/bash is stuck
at 3.2, but its easy to `brew install bash` to get the latest version in
/usr/local/bin/bash.
Make allows `-` in var names. (Actually it allows nearly all chars :).
Environment variables allow allow \w chars (alphanum and _).

Make inherits vars from the environment.

By using `-` over `_` we make clear which vars come from the environment
and which are local to the Makefile.
For consistency, added `-` where 2 words were made into one.
Added 2nd word to a few one word vars.
Only `.PHONY: test` is needed because we have a `test` dir.

The other .PHONY targets add little value and are noisy.
The generate target was not being run.

It did not cause an error becase it was hidden by a bad .PHONY target.
This makes things easier to understand and maintain.
and make them overridable by user.

Added a usage comment to top.

Note: Where env var overrides go before a command, Makefile var
overrides go after the `make` command.
Simplify to aot command
Using @ is for noisy or inconsequential commands.

It's important to see what make is actually running though.

Helps see obvious mistakes as well.
Let's us make these individually if needed.
'make test' runs both like before.

Before TEST-FILES was picking up the test suite glj file by mistake, I
believe.
a || b && c && d in bash always runs c and d, which was not the intent,
I believe.
The command `make` runs the first Makefile target.

Having the first target be called 'default' makes it obvious what is
going on.

I often specify no deps for the default target so running `make' prints:

    Nothing to be done for 'default'.
Add force=1 to the end of a make command to force rebuilds.

Adds update-clojure-sources to the front of `make all`.
For use in Makefiles that sit in front of this one.

For forks that are working on new AOT and platforms.
@ingydotnet ingydotnet requested a review from jfhamlin September 25, 2025 05:43
@ingydotnet
Copy link
Contributor Author

Rebased origin/main and added commit: 751490c

@jfhamlin jfhamlin merged commit 3b2afdd into glojurelang:main Sep 25, 2025
1 check passed
@ingydotnet ingydotnet deleted the makefile-refactor branch September 25, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants